#!/bin/sh -e

wd="`pwd`"
time="`date "+%s"`"
tmp_pkglist=$wd/tmp/pkglist-$time
. $wd/env


if [ ! "$cksum_file" ]; then
	echo ""
	echo -n " Enter path to the CHECKSUMS.md5 file: "
	read cksum_file
fi

if [ -f "$cksum_file"  ]; then
	mkdir -p $tmp_pkglist
	cp $cksum_file $tmp_pkglist/CHECKSUMS.md5
	# strip with result: "ap/ash-0.4.0-i386-1.tgz" as an example.
	cat $tmp_pkglist/CHECKSUMS.md5 | cut -d" " -f3|sed -e 's/^\.\///g'|grep tgz$ > $tmp_pkglist/CHECKSUMS.md5.stage1
	for p in `cat $tmp_pkglist/CHECKSUMS.md5.stage1`; do
		echo $p >> $tmp_pkglist/`dirname $p`.pkglist
	done
fi


# copy pkglists
# default 
dest=$wd/files/installcd-initrd/nemonico/files/packages/pkglist/default
echo " Copying pkglists for 'default' : $dest"
for l in $slackware_pkglist_default ; do
	cp $tmp_pkglist/$l.pkglist $dest
done

# full
dest=$wd/files/installcd-initrd/nemonico/files/packages/pkglist/full
echo " Copying pkglists for 'full' : $dest"
for l in $slackware_pkglist_full ; do
	cp $tmp_pkglist/$l.pkglist $dest
done

# no_x11
dest=$wd/files/installcd-initrd/nemonico/files/packages/pkglist/no_x11
echo " Copying pkglists for 'no_x11' : $dest"
for l in $slackware_pkglist_no_x11 ; do
	cp $tmp_pkglist/$l.pkglist $dest
done


echo ""
echo " The lists are at:  $tmp_pkglist "
echo ""
echo Done.

set +e

